package com.d0318;

import java.util.concurrent.TimeUnit;

public class Resourse2 {
    private Object syncObject1 = new Object();
    private Object syncObject2 = new Object();
    public void f() {
        System.out.println(Thread.currentThread().getName()+"not.............");
        synchronized (this){
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + "f()is running");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void g(){
        System.out.println(Thread.currentThread().getName()+"000000");
        synchronized (syncObject1) {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + "g()is running");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void h(){
        System.out.println(Thread.currentThread().getName()+"11111111");
        synchronized (syncObject2) {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + "h()is running");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        Resourse resourse = new Resourse();
        new Thread(()->resourse.f()).start();
        new Thread(()->resourse.g()).start();
        resourse.h();
    }
}
